import math

def change_ori_DEFtoOA(strs):
	# DEF/LEF to OA/DB
	ori_dict = {"N":"R0", "S":"R180", "W":"R90", "E":"R270", "FN":"MY", "FS":"MX", "FW":"MX90", "FE":"MY90"}
	return ori_dict[strs]

def change_ori_OAtoDEF(strs):
	ori_dict = {"R0":"N", "R180":"S", "R90":"W", "R270":"E", "MY":"FN", "MX":"FS", "MX90":"FW", "MY90":"FE"}
	return ori_dict[strs]

def replace_char(astr, achar, bchar):
	len_str = len(astr)
	alist = []
	for i in range(len_str):
		if astr[i] == achar:
			alist.append(i)
	
	if alist != []:
		for i in alist:
			astr = astr[:i]+bchar+astr[i+1:]
	return astr

def file_to_list(path):
	re_list = []
	with open(path, 'r') as f:
		for line in f.readlines():
			re_list.append(line[:-1].split(' '))	
	return re_list

def str_divide_units(strs,units):
	return str(float(int(strs)/int(units)))

def round_4(a):
	return round(float(a), 4)

def round_3(a):
	return round(float(a), 3)

def is_2_n(x):
	if x > 1:
		return math.log(x, 2)%1 == 0
	else:
		return False
	
def get_2_n(x):
	if x != 0 and  is_2_n(x):
		return get_2_n(x//2)+1
	else:
		return 0